<template>
  <main-wrap>
    <div class="msgListWrap">
      <div class="weui-form-preview mycard">
        <div class="weui-form-preview__hd">
          <div class="weui-form-preview__item">
            <label class="weui-form-preview__label">巡检人</label>
            <em class="weui-form-preview__value aright">{{patroller}}</em>
          </div>
        </div>
        <div class="weui-form-preview__bd">
          <div class="weui-form-preview__item">
            <label class="weui-form-preview__label black">巡检地点</label>
            <span class="weui-form-preview__value">{{addrtext}}</span>
          </div>
          <div class="weui-form-preview__item">
            <label class="weui-form-preview__label black">起止时间</label>
            <span class="weui-form-preview__value">{{timestr}}</span>
          </div>
          <div class="weui-form-preview__item">
            <label class="weui-form-preview__label black">提交时间</label>
            <span class="weui-form-preview__value">{{createtime}}</span>
          </div>
          <div class="weui-form-preview__item">
            <label class="weui-form-preview__label black">巡检描述</label>
            <span class="weui-form-preview__value">{{descri}}</span>
          </div>
          <div class="weui-form-preview__item">
            <label class="weui-form-preview__label black">上传图片</label>
            <div class="weui-form-preview__value attachwrap">
              <my-attachments :attachments="attachments" v-if="attachments.length > 0"></my-attachments>
            </div>
          </div>
        </div>
        <div class="weui-form-preview__ft">
          <router-link :to="'/patrollist'" class="weui-form-preview__btn weui-form-preview__btn_primary">返回</router-link>
        </div>
      </div>
    </div>
  </main-wrap>
</template>

<script>
import MainWrap from '@/components/mainWrap'
import MyAttachments from '@/components/myattachments'
export default {
  name: 'PatrolDetail',
  data () {
    return {
      pid: localStorage.curPatrolID,

      patroller: '',
      addrtext: '',
      attachments: [],
      descri: '',
      timestr: '',
      createtime: ''
    }
  },
  components: {
    MainWrap,
    MyAttachments
  },
  mounted () {
    this.cm.overscroll(document.querySelector('.msgListWrap'))
    this.getData()
  },
  methods: {
    getData () {
      this.cm.myajax('/api/inspection/info', {
        id: this.pid
      }, (data) => {
        data = data.tbInspection
        this.patroller = data.createByUserObj.name
        this.addrtext = data.place
        this.descri = data.inspectionResult
        this.createtime = data.ctime
        this.timestr = data.stime.substring(0, 16) + ' - ' + data.etime.substring(11, 16)
        this.attachments = data.attachments
      })
    }
  }
}
</script>

<style lang="stylus" scoped>
.weui-form-preview__item
  margin-top 1em

.weui-form-preview__ft
  margin-top .6rem

.weui-form-preview__bd
  .weui-form-preview__value
    text-align left
    padding-left 1em
    &.attachwrap
      padding-left 0
</style>
